export default defineEventHandler(async (event) => {
  const query = getQuery(event);
  const { origin, destination, strategy = 0, waypoints } = query;
  
  // 模拟延迟
  await new Promise(resolve => setTimeout(resolve, 600));
  
  try {
    if (!origin || !destination) {
      throw createError({
        statusCode: 400,
        statusMessage: '缺少必要参数：origin 和 destination'
      });
    }
    
    // 模拟路径规划数据
    const mockRouteData = {
      success: true,
      data: {
        origin: origin,
        destination: destination,
        strategy: strategy,
        waypoints: waypoints || '',
        distance: '5.2',
        duration: '1200',
        tolls: '0',
        toll_distance: '0',
        steps: [
          {
            instruction: '从起点出发，沿花城大道向东行驶',
            orientation: '东',
            distance: '500',
            tolls: '0',
            toll_distance: '0',
            toll_road: '',
            polyline: '113.289405,23.013125;113.290405,23.013125'
          },
          {
            instruction: '右转进入珠江新城路',
            orientation: '南',
            distance: '800',
            tolls: '0',
            toll_distance: '0',
            toll_road: '',
            polyline: '113.290405,23.013125;113.290405,23.005125'
          },
          {
            instruction: '左转进入广州大道',
            orientation: '东',
            distance: '1200',
            tolls: '0',
            toll_distance: '0',
            toll_road: '',
            polyline: '113.290405,23.005125;113.302405,23.005125'
          },
          {
            instruction: '继续直行到达目的地',
            orientation: '东',
            distance: '2700',
            tolls: '0',
            toll_distance: '0',
            toll_road: '',
            polyline: '113.302405,23.005125;113.329405,23.005125'
          }
        ],
        traffic: {
          status: '畅通',
          evaluation: '良好',
          expeditious: '0',
          congested: '0',
          blocked: '0',
          unknown: '0'
        }
      },
      message: '路径规划成功'
    };
    
    // 根据策略调整路径
    if (strategy === '1') {
      // 费用优先
      mockRouteData.data.distance = '6.1';
      mockRouteData.data.duration = '1400';
      mockRouteData.data.steps[2].instruction = '选择免费道路，绕行一段距离';
    } else if (strategy === '2') {
      // 距离优先
      mockRouteData.data.distance = '4.8';
      mockRouteData.data.duration = '1100';
      mockRouteData.data.steps[1].instruction = '选择最短路径，直接穿行';
    } else if (strategy === '3') {
      // 不走高速
      mockRouteData.data.distance = '7.2';
      mockRouteData.data.duration = '1600';
      mockRouteData.data.steps[2].instruction = '避开高速公路，选择城市道路';
    }
    
    return mockRouteData;
  } catch (error) {
    console.error('路径规划API模拟数据生成失败:', error);
    throw createError({
      statusCode: 500,
      statusMessage: '路径规划失败'
    });
  }
}); 